package CodingTest;

public class erfenfa {
    public static int commonBinarySearch(int[] arr,int key){
        int low = 0;
        int high = arr.length - 1;
        int middle = 0;

        if(key < arr[low] || key > arr[high] || low > high){
            return -1;
        }
        while(low <= high){
            middle = (low + high)/2;
            if(arr[middle] > key){
                high = middle -1;
            }else if (arr[middle] < key){
                low = middle + 1;
            }else{
                return middle;
            }
        }
        return -1;
    }
}
